from langchain.agents import  initialize_agent,AgentType,create_react_agent,AgentExecutor
from langchain_community.agent_toolkits.load_tools import load_tools
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.chains.conversation.base import ConversationChain

# pip install streamlit
# streamlit文档 https://docs.streamlit.io/develop/api-reference
import streamlit as st
st.title("这是一个streamlit的使用文件")




from base_util import init_model
llm = init_model()

if 'history' not in   st.session_state:
    st.session_state['history']=ConversationBufferMemory()

conversation = ConversationChain(llm=llm,memory=st.session_state['history'])

for i in conversation.memory.chat_memory.messages:
     st.chat_message(i.type).write(i.content)

if input := st.chat_input():
    # st.write(input)
    st.chat_message('user').write(input)
    # res = llm.invoke(input).content
    # st.chat_message('ai').write(res)
    res = conversation.invoke(input)
    st.chat_message('ai').write(res['response'])




